<?php

/**
 * NewsModule actions.
 *
 * @package    iEasy
 * @subpackage NewsModule
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class newsActions extends sfActions
{
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request)
    {
        $routing = $this->getContext()->getRouting();
        $this->pageUrl = $routing->getCurrentInternalUri();
    }

    public function executeDetail(sfWebRequest $request)
    {
        $this->newsId = $request->getParameter("id");
        $this->pageNo = $request->getParameter("page");
        if (!$this->pageNo || $this->pageNo == '') {
            $this->pageNo = 1;
        }

        $dbBase = new DbBase();
        $this->row_array = array();
        $this->contents = array();
        $sql = "update News set hit_i = (case hit_i when NULL then 1 else hit_i+1 end) where status_id !=1006 and news_id = " . $this->newsId;
        $dailyHitSql = "update News set daily_hit = (case daily_hit when NULL then 1 else daily_hit+1 end) where status_id !=1006 and news_id = " . $this->newsId;
        $weeklyHitSql = "update News set weekly_hit = (case weekly_hit when NULL then 1 else weekly_hit+1 end) where status_id !=1006 and news_id = " . $this->newsId;
        $dbBase->update($sql);
        $dbBase->update($dailyHitSql);
        $dbBase->update($weeklyHitSql);
        //echo $sql;

        $sql = "select news_id, title, keyword, body, author, publish_time as currentTime, hit_mask_i,hit_i, tag,  source,catalog_id,sub_catalog_id, brief,catalog_id, brief_title,short_comment,keyword  from News where status_id !=1006 and news_id = " . $this->newsId;
        //echo $sql;

        $this->row_array = $dbBase->getDataQuery($sql);
        if (count($this->row_array) > 0) {
            $this->row_array = $this->row_array[0];
            $catalog = Doctrine_Core::getTable("catalog")->find($this->row_array["catalog_id"]);

            $this->response->setTitle($this->row_array["title"] . "_新闻_" . $catalog->getDescription() . "_" . sfConfig::get("app_site_name"));
            $this->response->setKeywords($this->row_array["keyword"]);

            $pattern = "/<div style=\"page-break-after: always;?\">\s*<span style=\"display: none;?\">&nbsp;<\/span>\s*<\/div>/";
            $this->row_array["body"] = str_replace("<img border='0' src='/images/video_frame.jpg' />", "", strtr(preg_replace($pattern, "$$$$$$$", $this->row_array["body"]), array(
                                                                                                                                                                                   "\"" => "'",
                                                                                                                                                                                   "\r\n" => "\\r\\n",
                                                                                                                                                                                   "</script>" => "<\/script>",
                                                                                                                                                                                   "flvPlayer" => "",
                                                                                                                                                                                   "？代替" => "?")));

            //            $newsBody = $this->row_array["body"];
            //            $bodyarray = preg_split("$$$$$$$", $newsBody);
            //            $this->row_array["body"] = $bodyarray[0];
            //            if ($this->pageNo < count($bodyarray) && $this->pageNo > 0) {
            //                $this->newsBody = $bodyarray[$this->pageNo - 1];
            //            }
        }
        else
            return $this->renderText("该记录不存在。");
    }

    public function executeTest(sfWebRequest $request)
    {
        $routing = $this->getContext()->getRouting();
        $this->uri = $routing->getCurrentInternalUri();

    }

    public function executeList(sfWebRequest $request)
    {
        $routing = $this->getContext()->getRouting();
        $this->pageUrl = $routing->getCurrentInternalUri();
        //echo utility::getJavascript("alert('".$routing->getCurrentInternalUri()."');");
        $this->catalogId = $request->getParameter("catalogId");
        $this->subCatalogId = $request->getParameter("subCatalogId");
        $catalog = Doctrine_Core::getTable("catalog")->find($this->subCatalogId);
        $title = "头条";
        if ($catalog != null) {
            $title = $catalog->getDescription();
            if ($title == "明星")
                $title = "偶像追踪";
        }
        $catalog = Doctrine_Core::getTable("catalog")->find($this->catalogId);
        if ($catalog != null)
            $title = $title . "_新闻_" . $catalog->getDescription();
        $this->response->setTitle($title . "_" . sfConfig::get("app_site_name"));
    }
}
